<?php
namespace app\product\admin;
use app\system\admin\Admin;
use app\product\model\Project as ProjectModel;
use app\product\model\ProjectProduct as ProjectProductModel;
// use app\product\model\Brand as BrandModel;
// use app\product\model\Supplier as SupplierModel;
// use app\product\model\Unit as UnitModel;
class Project extends Admin
{
    protected $hisiModel = 'Project';//模型名称[通用添加、修改专用]
    protected $hisiTable = '';//表名称[通用添加、修改专用]
    protected $hisiAddScene = '';//添加数据验证场景名
    protected $hisiEditScene = '';//更新数据验证场景名

    public function index()
    {
        if ($this->request->isAjax()) {
            $where      = [];
            $page       = $this->request->param('page/d', 1);
            $limit      = $this->request->param('limit/d', 15);
            $name      = $this->request->param('name', '');
            if(!empty($name)){
                $where[] = ['name','like','%'.$name."%"];
            }
            $data['data'] = ProjectModel::where($where)
                            ->page($page)
                            ->limit($limit)
                            ->order('weigh asc,id desc')
                            ->select();

            $data['count'] = ProjectModel::where($where)->count('id');
            $data['code'] = 0;
            return json($data);

        }
        // 分组切换类型 0无需分组切换，1单个分组，2多个分组切换[无链接]，3多个分组切换[有链接]，具体请看application/example/view/layout.html
        $this->assign('hisiTabType', 0);
        // tab切换数据
        // $hisiTabData = [
        //     ['title' => '后台首页', 'url' => 'system/index/index'],
        // ];
        // current 可不传
        // $this->assign('hisiTabData', ['menu' => $hisiTabData, 'current' => 'system/index/index']);
        $this->assign('hisiTabData', '');
        return $this->fetch();
    }
    public function import()
    {
        if ($this->request->isAjax()) {
            $where      = [];
            $name = $this->request->param('name', '');
            if(!is_empty($name)){
                $where[] = ['name','like','%'.$name.'%'];
            }
            $data['data'] = ProjectModel::where($where)
                            ->order('weigh asc,id desc')
                            ->select();

            $data['count'] = ProjectModel::where($where)->count('id');
            $data['code'] = 0;
            return json($data);
        }
    }

}
